package com.example.interrupt;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.TimeUnit;

@Slf4j
public class MyDemo {
    public static final Object lock = new Object();

    public static void main(String[] args) {

        Thread t1 = new Thread(() -> {
            log.info("t1 hello");
            synchronized (lock) {
                try {
                    lock.wait();
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
            }

            try {
                TimeUnit.SECONDS.sleep(20);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            log.info("t1结束了");
        }, "t1");
        t1.start();

//        Thread t2 = new Thread(() -> {
//            synchronized (lock) {
//
//                log.info("t2 hello");
//
//            }
//            log.info("t2结束了");
//        }, "t2");
//        t2.start();

        try {
            // main线程
            TimeUnit.SECONDS.sleep(10);
            t1.interrupt();
        } catch (InterruptedException e) {
            throw new RuntimeException(e);
        }
    }
}
